using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PatchMakingTool
{
    public partial class UCSelectFile : UserControl
    {
        private string _filter;

        [Browsable(true)]
        [CategoryAttribute("File Browser Settings")]
        public string Filter
        {
            get { return _filter; }
            set { 
                _filter = value;
                this.openFileDialog.Filter = value;
            }
        }

        private string _filePath = string.Empty;

        public string FilePath
        {
            get { return _filePath; }
        }

        public UCSelectFile()
        {
            InitializeComponent();
        }

        public event EventHandler<FileSelectedEventArgs> FileSelected;

        protected virtual void OnFileSelected(FileSelectedEventArgs e)
        {
            if (FileSelected != null) FileSelected(this, e);
        }

        private void buttonBrowser_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBoxPath.Text = openFileDialog.FileName;
                _filePath = openFileDialog.FileName;
                OnFileSelected(new FileSelectedEventArgs(openFileDialog.FileName));
            }
        }

        public void Reset()
        {
            this.textBoxPath.Text = string.Empty;
            OnFileSelected(new FileSelectedEventArgs(string.Empty));
        }
    }

    public class FileSelectedEventArgs : System.EventArgs
    {
        public readonly string FilePath;

        public FileSelectedEventArgs(string filePath)
        {
            FilePath = filePath;            
        }
    }

}
